package com.oa.entities.flows;

import com.oa.common.enums.DateType;
import com.oa.common.enums.PassType;
import com.oa.common.enums.PersonType;
import com.oa.domain.UndeleteEntity;
import com.oa.entities.User;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

@Entity
@Table(name = "oa_personnel")
public class Personnel extends UndeleteEntity<Long> {
    /**
     *
     */
    private static final long serialVersionUID = -8443286341705824322L;

    /** 用户的id **/
    public static final String PERSONNEL_USER_ID="userId";

    /** 姓名 **/
    private String name;

    /** 用户 **/
    private User user;

    /** 用户的id **/
    private Long userId;

    /** 指定时间 **/
    private Long designationdate;

    /** 审核时间 **/
    private Long approvaldate;

    /** 批示 **/
    private String lnstructions;

    /** 公文 **/
    private Apps apps;

    /** 公文id **/
    private Long appsId;

    /** 流程 **/
    private Flow flow;

    /** 流程id **/
    private Long flowId;

    /** 超时类型 **/
    private int dateType;

    /** 审批方式 **/
    private int auditType;

    /** 通过方式 **/
    private int passType;

    /** 超时处理 **/
    private Long flowdate;

    /** 审核类型 **/
    private int personType;

    /**
     * 设置不使用超时
     */
    public void setDisableTime(){
        this.dateType= DateType.DISABLE_TIMEOUT.getCode();
    }

    /**
     * 设置超时通过
     */
    public void setTimeOutPass(){
        this.dateType= DateType.TIMEOUT_PASS.getCode();
    }

    /**
     * 设置超时拒绝
     *
     */
    public void setTimeOutFail(){
        this.dateType= DateType.TIMEOUT_FAIL.getCode();
    }


    /**
     * 设置单人通过
     */
    public void setOnePass(){
        this.passType= PassType.ONE_PASS.getCode();
    }

    /**
     * 设置未审核
     */
    public void setUnAudited(){
        this.personType= PersonType.UNAUDITED.getCode();
    }

    /**
     * 设置已审核
     */
    public void setAudit(){
        this.personType= PersonType.AUDIT.getCode();
    }

    /**
     * 设置拒绝
     */
    public void setRefause(){
        this.personType= PersonType.REFUSE.getCode();
    }

    /**
     * 设置退回
     *
     */
    public void setReturn(){
        this.personType= PersonType.RETURN.getCode();
    }

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return super.getId();
    }

    @Override
    public void setId(Long id) {
        super.setId(id);
    }

    @NotNull
    @Length(max = 64)
    @Column(nullable = false,length = 64)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id",nullable = false,updatable = false,insertable = false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Column(name = "user_id")
    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    @Column(nullable = false)
    public Long getDesignationdate() {
        return designationdate;
    }

    public void setDesignationdate(Long designationdate) {
        this.designationdate = designationdate;
    }

    @Column(nullable = false)
    public Long getApprovaldate() {
        return approvaldate;
    }

    public void setApprovaldate(Long approvaldate) {
        this.approvaldate = approvaldate;
    }

    @Column(name = "lnstructions")
    public String getLnstructions() {
        return lnstructions;
    }

    public void setLnstructions(String lnstructions) {
        this.lnstructions = lnstructions;
    }

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "apps_id",nullable = false,updatable = false,insertable = false)
    public Apps getApps() {
        return apps;
    }

    public void setApps(Apps apps) {
        this.apps = apps;
    }

    @Column(name = "apps_id")
    public Long getAppsId() {
        return appsId;
    }

    public void setAppsId(Long appsId) {
        this.appsId = appsId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "flow_id",nullable = false,updatable = false,insertable = false)
    public Flow getFlow() {
        return flow;
    }

    public void setFlow(Flow flow) {
        this.flow = flow;
    }

    @Column(name = "flow_id")
    public Long getFlowId() {
        return flowId;
    }

    public void setFlowId(Long flowId) {
        this.flowId = flowId;
    }

    @Column(name = "date_type",nullable = false)
    public int getDateType() {
        return dateType;
    }

    public void setDateType(int dateType) {
        this.dateType = dateType;
    }

    @Column(name = "audit_type",nullable = false)
    public int getAuditType() {
        return auditType;
    }

    public void setAuditType(int auditType) {
        this.auditType = auditType;
    }

    @Column(name = "pass_type",nullable = false)
    public int getPassType() {
        return passType;
    }

    public void setPassType(int passType) {
        this.passType = passType;
    }

    @Column(name = "flow_date",nullable = false)
    public Long getFlowdate() {
        return flowdate;
    }

    public void setFlowdate(Long flowdate) {
        this.flowdate = flowdate;
    }

    @Column(name = "person_type",nullable = false)
    public int getPersonType() {
        return personType;
    }

    public void setPersonType(int personType) {
        this.personType = personType;
    }
}
